home *** CD-ROM | disk | FTP | other *** search
- program TstHshT1;
-
- uses
- SysUtils,
- HashTbl1 in 'HashTbl1.pas';
-
- const
- ElementCount = 53;
-
- function CalcELFHash(const S : string) : integer;
- var
- G : longint;
- i : integer;
- begin
- Result := 0;
- for i := 1 to length(S) do begin
- Result := (Result shl 4) + ord(S[i]);
- G := Result and $F0000000;
- if (G <> 0) then
- Result := Result xor (G shr 24);
- Result := Result and (not G);
- end;
- end;
-
- const
- TPEmployees : array [0..32] of string[15] =
- ('Antypas', 'Bolduc', 'Brady',
- 'Bucknall', 'Cappellucci', 'Cope',
- 'DelRossi', 'Douglas', 'Fairweather',
- 'Foley', 'Frerking', 'Geiger',
- 'Ghinaudo', 'Horaz', 'Huffman',
- 'Hughes', 'Inman', 'Kokkonen',
- 'Larsen', 'Leier', 'Medlin',
- 'Milner', 'Phillips', 'Reisdorph',
- 'Roberts', 'Rogers', 'Rose',
- 'Salisbury', 'Trickey', 'Troxell',
- 'Turner', 'Warner', 'Welch');
-
- var
- i : integer;
- HashTable : ThtHashTableLinear;
-
- begin
- HashTable := ThtHashTableLinear.Create(ElementCount, CalcELFHash);
- try
- {add all employee names}
- for i := 0 to 32 do
- HashTable.Insert(TPEmployees[i], nil);
- HashTable.debugPrint('tstHash1.LOG', true);
- {delete the first nine employee names}
- for i := 0 to 9 do
- HashTable.Delete(TPEmployees[i]);
- HashTable.debugPrint('tstHash2.LOG', true);
- {add the first nine employee names back in reverse order}
- for i := 9 downto 0 do
- HashTable.Insert(TPEmployees[i], nil);
- HashTable.debugPrint('tstHash3.LOG', true);
- {delete the odd-numbered employee names}
- for i := 0 to 32 do
- if Odd(i) then
- HashTable.Delete(TPEmployees[i]);
- HashTable.debugPrint('tstHash4.LOG', false);
- {add the odd-numbered employee names >= 15 back}
- for i := 15 to 32 do
- if Odd(i) then
- HashTable.Insert(TPEmployees[i], nil);
- HashTable.debugPrint('tstHash5.LOG', false);
- {add the odd-numbered employee names < 15 back}
- for i := 0 to 14 do
- if Odd(i) then
- HashTable.Insert(TPEmployees[i], nil);
- HashTable.debugPrint('tstHash6.LOG', true);
- {empty the table}
- HashTable.Empty;
- HashTable.debugPrint('tstHash7.LOG', false);
- {fill the table with strings}
- for i := 0 to pred(ElementCount) do
- HashTable.Insert(Format('String%d', [i]), nil);
- HashTable.debugPrint('tstHash8.LOG', true);
- finally
- HashTable.Free;
- end;
- end.
-